package com.cy.pj.eiems.service.impl;

     import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.eiems.Exception.ServiceException;
import com.cy.pj.eiems.dao.CourseDao;
import com.cy.pj.eiems.entity.Course;
import com.cy.pj.eiems.service.CourseService;
import com.cy.pj.eiems.vo.PageObject;

@Service
public class CourseImpl implements CourseService{
	@Autowired
	private CourseDao courseDao;

	@Override
	public PageObject<Course> findObjects(String coursename, Integer pageCurrent) {
		//1.验证参数合法性
		if (pageCurrent == null||pageCurrent<1) {
			throw  new IllegalArgumentException("当前页码不正确");
		}	
		//2.基于条件查询总记录数并进行校验
		int rowCount = courseDao.getRowCount(coursename);
		if (rowCount==0) {
			throw new ServiceException("系统没有查到对应记录");
		}
		//3.基于条件查询当前页记录
		int pageSize=5;
		int startIndex=(pageCurrent-1)*pageSize;
		//4.对分页信息以及当前页记录进行封装
		List<Course> records = courseDao.findObjects(coursename, startIndex, pageSize);
		//5.返回封装结果
		return new PageObject<>(pageCurrent, pageSize, rowCount, records);
	}

}
